<template>
  <div :style="{ ...coreStyle.marginSame(8) }">
    <a-card>
      <a-form ref="taskExpressionParamFormQueryRef" :model="taskExpressionParamFormQueryModel" labelAlign="left" layout="vertical" :style="{ ...coreStyle.marginBottom(10) }">
        <a-row :gutter="16" v-show="!taskExpressionParamFormQueryVisible">
          <a-col :span="8">
            <a-form-item :style="{ ...coreStyle.marginBottom(-8) }">
              <a-input-search v-model:value="taskExpressionParamFormQueryModel.keySearchVo" placeholder="关键字搜索" :disabled="taskExpressionParamFormQuerySubmitting" @search="taskExpressionParamFormQuerySearch" />
            </a-form-item>
          </a-col>
          <a-col :span="16">
            <a-button type="link" :style="{ ...coreStyle.floatRight }" @click="taskExpressionParamFormQueryUpDown">
              展开
              <CoreIcon :icon="coreStyle.antBtnIconExpand" :size="14" />
            </a-button>
          </a-col>
        </a-row>
        <a-row :gutter="16" v-show="taskExpressionParamFormQueryVisible">
          <a-col :span="8">
            <a-form-item>
              <a-input-search v-model:value="taskExpressionParamFormQueryModel.keySearchVo" placeholder="关键字搜索" :disabled="taskExpressionParamFormQuerySubmitting" @search="taskExpressionParamFormQuerySearch" />
            </a-form-item>
          </a-col>
          <a-col :span="16">
          </a-col>
          <a-col :span="8">
            <a-form-item label="参数名">
              <a-input v-model:value="taskExpressionParamFormQueryModel.paramNameAndLike" placeholder="输入参数名" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="参数值">
              <a-input v-model:value="taskExpressionParamFormQueryModel.paramValueAndLike" placeholder="输入参数值" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="排序权重">
              <a-input-number v-model:value="taskExpressionParamFormQueryModel.weightOrder" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="外键Id">
              <a-input v-model:value="taskExpressionParamFormQueryModel.fkidAndLike" placeholder="输入外键Id" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-space :style="{ ...coreStyle.floatRight }">
              <a-button type="dashed" :style="{ ...coreStyle.antBtnReset }" @click="taskExpressionParamFormQueryReset">
                <CoreIcon :icon="coreStyle.antBtnIconReset" :size="14" />
                重置
              </a-button>
              <a-button :loading="taskExpressionParamFormQuerySubmitting" type="dashed" :style="{ ...coreStyle.antBtnQuery }" @click="taskExpressionParamFormQuerySearch">
                <CoreIcon :icon="coreStyle.antBtnIconQuery" :size="14" />
                查询
              </a-button>
              <a-button type="dashed" ghost :style="{ ...coreStyle.antBtnRetract }" @click="taskExpressionParamFormQueryUpDown">
                收起
                <CoreIcon :icon="coreStyle.antBtnIconRetract" :size="14" />
              </a-button>
            </a-space>
          </a-col>
        </a-row>
      </a-form>
      <a-space>
        <a-button type="dashed" :style="{ ...coreStyle.antBtnAdd }" @click="taskExpressionParamAdd">
          <CoreIcon :icon="coreStyle.antBtnIconAdd" :size="14" />
          新增
        </a-button>
        <a-button v-if="taskExpressionParamListSelectLength === 1" type="dashed" :style="{ ...coreStyle.antBtnUpdate }" @click="taskExpressionParamUpdate">
          <CoreIcon :icon="coreStyle.antBtnIconUpdate" :size="14" />
          修改
        </a-button>
        <a-popconfirm v-if="taskExpressionParamListSelectLength > 0" title="确认删除？" okType="dashed" placement="bottom" @confirm="taskExpressionParamDelete">
          <a-button type="dashed" :style="{ ...coreStyle.antBtnDelete }">
            <CoreIcon :icon="coreStyle.antBtnIconDelete" :size="14" />
            删除
          </a-button>
        </a-popconfirm>
        <a-button v-if="taskExpressionParamListSelectLength === 1" type="dashed" :style="{ ...coreStyle.antBtnDetail }" @click="taskExpressionParamDetailInfo">
          <CoreIcon :icon="coreStyle.antBtnIconDetail" :size="14" />
          详情
        </a-button>
      </a-space>
      <a-space :style="{ ...coreStyle.floatRight }">
        <a-button type="dashed" :style="{ ...coreStyle.antBtnTemplateDownload }" @click="taskExpressionParamTemplateDownload">
          <CoreIcon :icon="coreStyle.antBtnIconTemplateDownload" :size="14" />
          模版下载
        </a-button>
        <a-button type="dashed" :style="{ ...coreStyle.antBtnImport }" @click="taskExpressionParamDataImport">
          <CoreIcon :icon="coreStyle.antBtnIconImport" :size="14" />
          导入
        </a-button>
        <a-button type="dashed" :style="{ ...coreStyle.antBtnExport }" @click="taskExpressionParamDataExport">
          <CoreIcon :icon="coreStyle.antBtnIconExport" :size="14" />
          导出
        </a-button>
        <a-button type="dashed" ghost shape="circle" :style="{ ...coreStyle.antBtnRefresh }" @click="taskExpressionParamListGetDataSet">
          <CoreIcon :icon="coreStyle.antBtnIconRefresh" :size="22" />
        </a-button>
      </a-space>
      <a-table
        rowKey="id"
        :columns="taskExpressionParamListColumns"
        :data-source="taskExpressionParamListDataSet"
        :loading="taskExpressionParamListLoading"
        :pagination="false"
        bordered
        :customRow="taskExpressionParamListCustomRow"
        :row-selection="{ fixed: true, selectedRowKeys: taskExpressionParamListSelectedRowKeys, onChange: taskExpressionParamListRowOnChange }"
        :scroll="{ x: '100%', y: 550 }"
        :style="{ ...coreStyle.marginTop(10) }"
      >
      </a-table>
      <a-pagination
        v-model:current="taskExpressionParamListDataPage"
        v-model:pageSize="taskExpressionParamListDataRows"
        :total="taskExpressionParamListDataCount"
        show-size-changer
        show-quick-jumper
        :page-size-options="[ ...coreStyle.antdPaginationPageSizeOptions ]"
        :show-total="(total, range) => coreStyle.antdPaginationShowTotal(total, range)"
        :style="{ ...coreStyle.marginTop(10), ...coreStyle.textAlignCenter }"
        @change="taskExpressionParamListPaginationChange"
        @showSizeChange="taskExpressionParamListPaginationShowSizeChange"
        v-if="taskExpressionParamListPaginationVisible"
      >
      </a-pagination>
      <p :style="{ ...coreStyle.marginTop(14), ...coreStyle.marginBottom(6), ...coreStyle.textAlignCenter }" v-if="!taskExpressionParamListPaginationVisible">
        {{ coreStyle.antdPaginationShowTotal(taskExpressionParamListDataCount) }}
      </p>
    </a-card>
    <a-drawer
      v-model:visible="taskExpressionParamEditDrawerVisible"
      title="编辑任务公式参数信息"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 30, 0) }"
      @close="taskExpressionParamEditDrawerOnClose"
    >
      <a-form ref="taskExpressionParamFormRef" :model="taskExpressionParamFormModel" :rules="taskExpressionParamFormRules" labelAlign="left" layout="vertical">
        <a-row :gutter="16">
          <a-col :span="12">
            <a-form-item label="参数名" name="paramName">
              <a-input v-model:value="taskExpressionParamFormModel.paramName" placeholder="输入参数名" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="参数值" name="paramValue">
              <a-input v-model:value="taskExpressionParamFormModel.paramValue" placeholder="输入参数值" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="排序权重" name="weightOrder">
              <a-input-number v-model:value="taskExpressionParamFormModel.weightOrder" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="外键Id" name="fkid">
              <a-input v-model:value="taskExpressionParamFormModel.fkid" placeholder="输入外键Id" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnReset }" @click="taskExpressionParamFormReset">
            <CoreIcon :icon="coreStyle.antBtnIconReset" :size="14" />
            重置
          </a-button>
          <a-button :loading="taskExpressionParamFormSaveSubmitting" type="dashed" :style="{ ...coreStyle.antBtnNextAdd }" @click="taskExpressionParamFormNextAdd">
            <CoreIcon :icon="coreStyle.antBtnIconNextAdd" :size="14" />
            继续录入
          </a-button>
          <a-button :loading="taskExpressionParamFormSaveSubmitting" type="dashed" :style="{ ...coreStyle.antBtnSave }" @click="taskExpressionParamFormSave">
            <CoreIcon :icon="coreStyle.antBtnIconSave" :size="14" />
            保存
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="taskExpressionParamDetailDrawerVisible"
      title="任务公式参数详细信息"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 30, 0) }"
    >
      <a-space direction="vertical" :size="20" :style="{ ...coreStyle.width('100%') }">
        <a-descriptions title="基础信息" :column="2" bordered>
          <a-descriptions-item label="参数名" :span="1">{{ taskExpressionParamDetailModel.paramName }}</a-descriptions-item>
          <a-descriptions-item label="参数值" :span="1">{{ taskExpressionParamDetailModel.paramValue }}</a-descriptions-item>
          <a-descriptions-item label="排序权重" :span="1">{{ taskExpressionParamDetailModel.weightOrder }}</a-descriptions-item>
          <a-descriptions-item label="外键Id" :span="1">{{ taskExpressionParamDetailModel.fkid }}</a-descriptions-item>
        </a-descriptions>
      </a-space>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnUpdate }" @click="taskExpressionParamDetailUpdate">
            <CoreIcon :icon="coreStyle.antBtnIconUpdate" :size="14" />
            修改
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="taskExpressionParamDataImportDrawerVisible"
      title="任务公式参数数据导入"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 50, 0) }"
    >
      <a-row :gutter="16">
        <a-col :span="24">
          <FileUpload ref="taskExpressionParamDataImportFileUploadRef" :fileModule="taskExpressionParamDataImportFileModule" @change="taskExpressionParamDataImportFileUploadChange" />
          <a-input v-model:value="taskExpressionParamDataImportFileUrl" disabled addonBefore="导入文件url:" placeholder="输入导入文件url">
            <template #addonAfter>
              <a-button type="link" size="small" @click="taskExpressionParamDataImportFileUrlSelectFileClick">选择文件</a-button>
            </template>
          </a-input>
        </a-col>
      </a-row>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button :loading="taskExpressionParamDataImportSaveSubmitting" type="dashed" :style="{ ...coreStyle.antBtnImportData }" @click="taskExpressionParamToDataImport">
            <CoreIcon :icon="coreStyle.antBtnIconImportData" :size="14" />
            导入数据
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="taskExpressionParamDataImportFileSelectDrawerVisible"
      title="文件选择"
      placement="right"
      :closable="false"
      destroyOnClose
      :width="'80%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 0, 0) }"
    >
      <FileSelect :fileModule="taskExpressionParamDataImportFileModule" @change="taskExpressionParamDataImportFileSelectChange" />
    </a-drawer>
    <a-drawer
      v-model:visible="taskExpressionParamDataExportDrawerVisible"
      title="任务公式参数数据导出"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 50, 0) }"
    >
      <DataExportColumnSelect :optionalDataExportFieldList="taskExpressionParamOptionalDataExportFieldList" :selectedDataExportFieldList="taskExpressionParamSelectedDataExportFieldList" />
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnQueryDataExport }" @click="taskExpressionParamToDataExport(false)">
            <CoreIcon :icon="coreStyle.antBtnIconQueryDataExport" :size="14" />
            查询数据导出
          </a-button>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnAllDataExport }" @click="taskExpressionParamToDataExport(true)">
            <CoreIcon :icon="coreStyle.antBtnIconAllDataExport" :size="14" />
            全部数据导出
          </a-button>
        </a-space>
      </div>
    </a-drawer>
  </div>
</template>

<script lang="ts">
import { Options, Vue } from 'vue-class-component'
import { mapStores } from 'pinia'
import { useCoreToolStore } from '/@/store/modules/cn/core/tool/coreToolStore'
import type { Res } from '/@/tool/Res'
import type { Param } from '/@/tool/Param'

import type { DataExportFieldAO } from '/@/model/cn/core/tool/ao/DataExportFieldAO'
import type { DataExportAO } from '/@/model/cn/core/tool/ao/DataExportAO'
import { toDataExportAO } from '/@/model/cn/core/tool/ao/DataExportAO'

import { useTaskExpressionParamStore } from '/@/store/modules/cn/core/kpis/taskExpressionParamStore'

import type { TaskExpressionParam } from '/@/model/cn/core/kpis/eo/TaskExpressionParam'
import { toTaskExpressionParam } from '/@/model/cn/core/kpis/eo/TaskExpressionParam'

import type { TaskExpressionParamQO } from '/@/model/cn/core/kpis/qo/TaskExpressionParamQO'
import { toTaskExpressionParamQO } from '/@/model/cn/core/kpis/qo/TaskExpressionParamQO'

import type { TaskExpressionParamVO } from '/@/model/cn/core/kpis/vo/TaskExpressionParamVO'
import { toTaskExpressionParamVO } from '/@/model/cn/core/kpis/vo/TaskExpressionParamVO'

@Options({
  name: 'TaskExpressionParam',
  components: {
  },
  computed: {
    ...mapStores(useCoreToolStore, useTaskExpressionParamStore),
  },
})
export default class TaskExpressionParam extends Vue {

  taskExpressionParamListDataSet: Array<TaskExpressionParamVO> = []

  taskExpressionParamListColumns: Array<object> = [
    {
      title: '参数名',
      dataIndex: 'paramName',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '参数值',
      dataIndex: 'paramValue',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '排序权重',
      dataIndex: 'weightOrder',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '外键Id',
      dataIndex: 'fkid',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
  ]

  taskExpressionParamListLoading: boolean = false

  taskExpressionParamListSelectedRowKeys: string[] = []

  taskExpressionParamListSelectData: Array<TaskExpressionParamVO> = []

  taskExpressionParamListSelectLength: number = 0

  taskExpressionParamListSelectCurrentRowIndex: number = -1

  taskExpressionParamListSelectCurrentRowData: TaskExpressionParamVO = toTaskExpressionParamVO()

  taskExpressionParamListPaginationVisible: boolean = true

  taskExpressionParamListDataPage: number = 1

  taskExpressionParamListDataRows: number = 10

  taskExpressionParamListDataCount: number = 0

  taskExpressionParamListRowClickTimeout: number | null = null

  taskExpressionParamListRowOnChange(selectedRowKeys, selectedRows) {
    this.taskExpressionParamListSelectedRowKeys = [ ...selectedRowKeys ]
    this.taskExpressionParamListSelectData = [ ...selectedRows ]
    this.taskExpressionParamListSelectLength = selectedRows.length
  }

  taskExpressionParamListCustomRow(record, index) {
    return {
      'class': index === this.taskExpressionParamListSelectCurrentRowIndex ? 'ant-table-row-selected' : '',
      onClick: (event) => {
        if (this.taskExpressionParamListRowClickTimeout) {
          clearTimeout(this.taskExpressionParamListRowClickTimeout)
          this.taskExpressionParamListRowClickTimeout = null
        } else {
          this.taskExpressionParamListRowClickTimeout = setTimeout(() => {
            this.taskExpressionParamListRowClickTimeout = null
            this.taskExpressionParamListSelectCurrentRowIndex = index
            this.taskExpressionParamListSelectCurrentRowData = { ...record }
            let selectedRowKeys = [ ...this.taskExpressionParamListSelectedRowKeys ]
            let selectedRows = [ ...this.taskExpressionParamListSelectData ]
            if (selectedRowKeys.includes(record.id)) {
              this.taskExpressionParamListRowOnChange([ ...selectedRowKeys.filter(eo => { return eo !== record.id }) ], [ ...selectedRows.filter(eo => { return eo.id !== record.id }) ])
            } else {
              selectedRowKeys.push(record.id)
              selectedRows.push(record)
              this.taskExpressionParamListRowOnChange([ ...new Set(selectedRowKeys) ], [ ...new Set(selectedRows) ])
            }
          }, 200)
        }
      },
      onDblclick: (event) => {
        this.taskExpressionParamStore.pkVo(this.$toParam<TaskExpressionParamQO>({ id: record.id } as TaskExpressionParamQO)).then((res: Res<TaskExpressionParamVO>) => {
          if (res.succ) {
            this.taskExpressionParamDetailModel = { ...res.data[0] }
            this.taskExpressionParamDetailDrawerVisible = true
          } else {
            this.$message.error(res.msg, 6)
          }
        })
      },
    }
  }

  taskExpressionParamListGetDataSet() {
    this.taskExpressionParamListLoading = true
    this.taskExpressionParamListRowOnChange([], [])
    this.taskExpressionParamListSelectCurrentRowIndex = -1
    this.taskExpressionParamListSelectCurrentRowData = toTaskExpressionParamVO()
    this.taskExpressionParamStore.pagingVo(this.$toParam<TaskExpressionParamQO>({ weightOrderAsc: 'y' } as TaskExpressionParamQO, this.taskExpressionParamListDataPage, this.taskExpressionParamListDataRows)).then((res: Res<TaskExpressionParamVO>) => {
      if (res.succ) {
        this.taskExpressionParamListPaginationVisible = true
        this.taskExpressionParamListDataSet = [ ...res.data ]
        this.taskExpressionParamListDataCount = res.count
        setTimeout(() => { this.taskExpressionParamListLoading = false }, 500)
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.taskExpressionParamListLoading = false }, 500)
      }
    }).catch(err => {
      setTimeout(() => { this.taskExpressionParamListLoading = false }, 500)
    })
  }

  taskExpressionParamListPaginationChange() {
    this.taskExpressionParamListGetDataSet()
  }

  taskExpressionParamListPaginationShowSizeChange() {
    this.taskExpressionParamListGetDataSet()
  }

  taskExpressionParamFormQueryVisible: boolean = false

  taskExpressionParamFormQuerySubmitting: boolean = false

  taskExpressionParamFormQueryModel: TaskExpressionParamQO = toTaskExpressionParamQO()

  taskExpressionParamFormQueryUpDown() {
    this.taskExpressionParamFormQueryVisible = !this.taskExpressionParamFormQueryVisible
  }

  taskExpressionParamFormQueryReset() {
    if (this.$refs.taskExpressionParamFormQueryRef) {
      this.$refs.taskExpressionParamFormQueryRef.resetFields()
      this.taskExpressionParamFormQueryModel = toTaskExpressionParamQO()
    }
  }

  taskExpressionParamFormQuerySearch() {
    this.taskExpressionParamFormQuerySubmitting = true
    this.taskExpressionParamListLoading = true
    this.taskExpressionParamListRowOnChange([], [])
    this.taskExpressionParamListSelectCurrentRowIndex = -1
    this.taskExpressionParamListSelectCurrentRowData = toTaskExpressionParamVO()
    this.taskExpressionParamStore.queryVo(this.$toParam<TaskExpressionParamQO>(this.$toSearch({ ...this.taskExpressionParamFormQueryModel }))).then((res: Res<TaskExpressionParamVO>) => {
      if (res.succ) {
        this.taskExpressionParamListPaginationVisible = false
        this.taskExpressionParamListDataSet = [ ...res.data ]
        this.taskExpressionParamListDataCount = res.count
        setTimeout(() => { this.taskExpressionParamFormQuerySubmitting = false }, 5000)
        setTimeout(() => { this.taskExpressionParamListLoading = false }, 500)
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.taskExpressionParamFormQuerySubmitting = false }, 5000)
        setTimeout(() => { this.taskExpressionParamListLoading = false }, 500)
      }
    }).catch(err => {
      setTimeout(() => { this.taskExpressionParamFormQuerySubmitting = false }, 5000)
      setTimeout(() => { this.taskExpressionParamListLoading = false }, 500)
    })
  }

  taskExpressionParamEditDrawerVisible: boolean = false

  taskExpressionParamFormSaveSubmitting: boolean = false

  taskExpressionParamFormSaveContinue: boolean = false

  taskExpressionParamFormModel: TaskExpressionParam = toTaskExpressionParam()

  taskExpressionParamFormRules: object = {
    // paramName: [
    //   { type: 'string', required: true, message: '参数名不能为空！', trigger: ['change', 'blur'] },
    // ],
    // paramValue: [
    //   { type: 'string', required: true, message: '参数值不能为空！', trigger: ['change', 'blur'] },
    // ],
    // weightOrder: [
    //   { type: 'number', required: true, message: '排序权重不能为空！', trigger: ['change', 'blur'] },
    // ],
    // fkid: [
    //   { type: 'string', required: true, message: '外键Id不能为空！', trigger: ['change', 'blur'] },
    // ],
  }

  taskExpressionParamFormReset() {
    if (this.$refs.taskExpressionParamFormRef) {
      this.$refs.taskExpressionParamFormRef.resetFields()
      this.taskExpressionParamFormModel = toTaskExpressionParam()
    }
  }

  taskExpressionParamFormSubmit() {
    this.taskExpressionParamFormSaveSubmitting = true
    this.$refs.taskExpressionParamFormRef.validate().then(() => {
      if (this.taskExpressionParamFormModel.id) {
        this.taskExpressionParamStore.update(this.$toParam<TaskExpressionParam>(this.taskExpressionParamFormModel)).then((res: Res<TaskExpressionParam>) => {
          if (res.succ) {
            this.$message.success(res.msg, 3)
            this.taskExpressionParamFormReset()
            this.taskExpressionParamFormSaveSubmitting = false
            if (!this.taskExpressionParamFormSaveContinue) {
              this.taskExpressionParamEditDrawerVisible = false
              this.taskExpressionParamListGetDataSet()
            }
          } else {
            this.$message.error(res.msg, 6)
            setTimeout(() => { this.taskExpressionParamFormSaveSubmitting = false }, 3000)
          }
        }).catch(err => {
          setTimeout(() => { this.taskExpressionParamFormSaveSubmitting = false }, 3000)
        })
      } else {
        this.taskExpressionParamStore.save(this.$toParam<TaskExpressionParam>(this.taskExpressionParamFormModel)).then((res: Res<TaskExpressionParam>) => {
          if (res.succ) {
            this.$message.success(res.msg, 3)
            this.taskExpressionParamFormReset()
            this.taskExpressionParamFormSaveSubmitting = false
            if (!this.taskExpressionParamFormSaveContinue) {
              this.taskExpressionParamEditDrawerVisible = false
              this.taskExpressionParamListGetDataSet()
            }
          } else {
            this.$message.error(res.msg, 6)
            setTimeout(() => { this.taskExpressionParamFormSaveSubmitting = false }, 3000)
          }
        }).catch(err => {
          setTimeout(() => { this.taskExpressionParamFormSaveSubmitting = false }, 3000)
        })
      }
    }).catch(() => {
      setTimeout(() => { this.taskExpressionParamFormSaveSubmitting = false }, 3000)
    })
  }

  taskExpressionParamFormSave() {
    this.taskExpressionParamFormSaveContinue = false
    this.taskExpressionParamFormSubmit()
  }

  taskExpressionParamFormNextAdd() {
    this.taskExpressionParamFormSaveContinue = true
    this.taskExpressionParamFormSubmit()
  }

  taskExpressionParamAdd() {
    if (this.taskExpressionParamFormModel.id) {
      this.taskExpressionParamFormReset()
    }
    this.taskExpressionParamEditDrawerVisible = true
  }

  taskExpressionParamUpdate() {
    this.taskExpressionParamStore.pk(this.$toParam<TaskExpressionParamQO>({ id: this.taskExpressionParamListSelectData[0].id } as TaskExpressionParamQO)).then((res: Res<TaskExpressionParam>) => {
      if (res.succ) {
        this.taskExpressionParamFormReset()
        this.taskExpressionParamFormModel = { ...res.data[0] }
        this.taskExpressionParamEditDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  taskExpressionParamEditDrawerOnClose() {
    if (this.taskExpressionParamFormSaveContinue) {
      this.taskExpressionParamFormSaveContinue = false
      this.taskExpressionParamListGetDataSet()
    }
  }

  taskExpressionParamDelete() {
    let param: Array<TaskExpressionParam> = []
    this.taskExpressionParamListSelectData.forEach((eo: TaskExpressionParamVO) => {
      param.push({ id: eo.id } as TaskExpressionParam)
    })
    this.taskExpressionParamStore.removeBatch(this.$toParam<TaskExpressionParam>(param)).then((res: Res<TaskExpressionParam>) => {
      if (res.succ) {
        this.$message.success(res.msg, 3)
        this.taskExpressionParamListGetDataSet()
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  taskExpressionParamDetailDrawerVisible: boolean = false

  taskExpressionParamDetailModel: TaskExpressionParamVO = toTaskExpressionParamVO()

  taskExpressionParamDetailInfo() {
    this.taskExpressionParamStore.pkVo(this.$toParam<TaskExpressionParamQO>({ id: this.taskExpressionParamListSelectData[0].id } as TaskExpressionParamQO)).then((res: Res<TaskExpressionParamVO>) => {
      if (res.succ) {
        this.taskExpressionParamDetailModel = { ...res.data[0] }
        this.taskExpressionParamDetailDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  taskExpressionParamDetailUpdate() {
    this.taskExpressionParamStore.pk(this.$toParam<TaskExpressionParamQO>({ id: this.taskExpressionParamDetailModel.id } as TaskExpressionParamQO)).then((res: Res<TaskExpressionParam>) => {
      if (res.succ) {
        this.taskExpressionParamFormReset()
        this.taskExpressionParamFormModel = { ...res.data[0] }
        this.taskExpressionParamDetailDrawerVisible = false
        this.taskExpressionParamEditDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  taskExpressionParamTemplateDownload() {
    this.coreToolStore.getValueByConfKey('defaultDataImportTemplate').then((res: string) => {
      window.open(this.coreToolStore.getFileFullUrl(res), '_blank')
    })
  }

  taskExpressionParamDataImportDrawerVisible: boolean = false

  taskExpressionParamDataImportFileSelectDrawerVisible: boolean = false

  taskExpressionParamDataImportFileModule: string = 'dataImport'

  taskExpressionParamDataImportFileUrl: string = ''

  taskExpressionParamDataImportSaveSubmitting: boolean = false

  taskExpressionParamDataImport() {
    this.taskExpressionParamDataImportDrawerVisible = true
  }

  taskExpressionParamDataImportFileUploadChange(value) {
    this.taskExpressionParamDataImportFileUrl = value
  }

  taskExpressionParamDataImportFileUrlSelectFileClick() {
    this.taskExpressionParamDataImportFileSelectDrawerVisible = true
  }

  taskExpressionParamDataImportFileSelectChange(fileUrl) {
    this.taskExpressionParamDataImportFileUrl = fileUrl
    this.taskExpressionParamDataImportFileSelectDrawerVisible = false
  }

  taskExpressionParamToDataImport() {
    this.taskExpressionParamDataImportSaveSubmitting = true
    this.taskExpressionParamStore.dataImport(this.$toParam<string>(this.taskExpressionParamDataImportFileUrl)).then((res: Res<TaskExpressionParam>) => {
      if (res.succ) {
        this.$message.success(res.msg, 3)
        this.$refs.taskExpressionParamDataImportFileUploadRef.resetFiles()
        this.taskExpressionParamDataImportFileUrl = ''
        this.taskExpressionParamDataImportSaveSubmitting = false
        this.taskExpressionParamDataImportDrawerVisible = false
        this.taskExpressionParamListGetDataSet()
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.taskExpressionParamDataImportSaveSubmitting = false }, 3000)
      }
    }).catch(err => {
      setTimeout(() => { this.taskExpressionParamDataImportSaveSubmitting = false }, 3000)
    })
  }

  taskExpressionParamDataExportDrawerVisible: boolean = false

  taskExpressionParamOptionalDataExportFieldList: Array<DataExportFieldAO> = [
    {
      fieldName: 'paramName',
      fieldComment: '参数名',
    },
    {
      fieldName: 'paramValue',
      fieldComment: '参数值',
    },
    {
      fieldName: 'weightOrder',
      fieldComment: '排序权重',
    },
    {
      fieldName: 'fkid',
      fieldComment: '外键Id',
    },
  ]

  taskExpressionParamSelectedDataExportFieldList: Array<DataExportFieldAO> = []

  taskExpressionParamDataExport() {
    this.taskExpressionParamDataExportDrawerVisible = true
  }

  taskExpressionParamToDataExport(allData: boolean) {
    this.taskExpressionParamStore.dataExport(this.$toParam<DataExportAO<TaskExpressionParamQO>>(toDataExportAO(this.taskExpressionParamSelectedDataExportFieldList, allData ? { weightOrderAsc: 'y' } as TaskExpressionParamQO : this.$toSearch({ ...this.taskExpressionParamFormQueryModel }), '任务公式参数信息数据导出.xlsx'))).then((res: Res<string>) => {
      if (res.succ) {
        window.open(this.coreToolStore.getFileFullUrl(res.data[0]), '_blank')
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  mounted() {
    this.taskExpressionParamListGetDataSet()
  }

}
</script>

<style scoped lang="less">

</style>
